package com.socodethis.spaceex.math;

import com.badlogic.gdx.Gdx;

public class cPoint {
	private float x;
	private float y;
	public cPoint(cPoint point){
		this(point.x, point.y);
	}
	public cPoint(){
		this.x=0;
		this.y=0;
	}
	public cPoint(float x, float y){
		this.x = x;
		this.y = y;
	}
	public float getX(){
		return this.x;
	}
	public float getY(){
		return this.y;
	}
	public cPoint getDifference(cPoint point){
		return new cPoint(Math.abs(this.x-point.getX()),Math.abs(this.y-point.getY()));
	}
	public int getXDistance(cPoint point){
		return (int) Math.abs(this.getX()-point.getX());
	}
	public int getYDistance(cPoint point){
		return (int) Math.abs(this.getY()-point.getY());
	}
	public int getEucDistance(cPoint point){
		return (int) Math.sqrt(Math.pow(this.x-point.getX(), 2)+Math.pow(this.y-point.getY(), 2));
	}
	public boolean getNextTo(cPoint point){
		return (Math.abs(this.x-point.getX()) + Math.abs(this.y-point.getY())) <=2 ? true:false;
	}
	public void setPoint(float x, float y){
		this.x = x;
		this.y = y;
	}
	public boolean inSquare(float x, float y, float x2, float y2){
		cPoint big, small;
		if(x >= x2){
			if(y >= y2){
				big = new cPoint(x,y);
				small = new cPoint(x2,y2);
			}else{
				big = new cPoint(x,y2);
				small = new cPoint(x2,y);
			}
		}else{
			if(y >= y2){
				big = new cPoint(x2,y);
				small = new cPoint(x,y2);
			}else{
				big = new cPoint(x2,y2);
				small = new cPoint(x,y);
			}
		}
		if(this.x >= small.getX() && this.y >= small.getY() && this.x<=big.getX() && this.y<=big.getY()){
			//System.out.println("Big-Small");
			//big.printPoint();
			//small.printPoint();
			return true;
		}
		return false;
	}
	public boolean cEquals(cPoint a){
		return (this.getX() == a.getX() && this.getY() == a.getY());
	}
	public void printPoint(){
		Gdx.app.log("cPoint","X: " + this.x  + " Y: " + this.y);
	}
	public void scalePoint(float scale){
		this.x *= scale;
		this.y *= scale;
	}
	public cPoint addPoints(cPoint point){
		cPoint temp = new cPoint(this);
		temp.x += point.x;
		temp.y += point.y;
		return temp;
	}
	public void addPointsNoNewVar(cPoint point){
		this.x += point.x;
		this.y += point.y;
	}
	public cPoint subPoints(cPoint point){
		cPoint temp = new cPoint(this);
		temp.x -= point.x;
		temp.y -= point.y;
		return temp;
	}
}
